package com.lyf.core.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.viewbinding.ViewBinding;

import com.lyf.core.R;
import com.lyf.core.presenter.BasePresenter;


public abstract class BaseMvpActivity<VB extends ViewBinding, T extends BasePresenter> extends BaseActivity<VB> {

    protected T mPresenter;
    public Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        mContext = this;
        super.onCreate(savedInstanceState);
        mPresenter = getPresenter();
        if (mPresenter != null) {
            mPresenter.attachView(this);
            mPresenter.addObserver(bindToLifecycle());
        }
        initData();
    }

    protected void refreshData() {
    }

    /**
     * activity动画的设置
     */

    public void startActivityByLeft(Intent intent) {
        startActivity(intent);
        overridePendingTransition(R.anim.aim_common_right_in,
                R.anim.aim_common_left_out);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mPresenter != null) {
            refreshData();
        }
    }

    protected void initData() {
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.detachView();
        }
    }

    public abstract T getPresenter();
}
